package org.jeecg.modules.bill.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.bill.entity.MedicineBuyer;
import org.jeecg.modules.bill.mapper.MedicineBuyerMapper;
import org.jeecg.modules.bill.service.MedicineBuyerService;
import org.jeecg.modules.stock.entity.MedicineStock;
import org.jeecg.modules.stock.mapper.MedicineStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: 药品进货表表
 * @Author: 孔小波
 * @Date:   2020-01-15
 * @Version: V1.0
 */
@Service
public class MedicineBuyerServiceImpl extends ServiceImpl<MedicineBuyerMapper, MedicineBuyer> implements MedicineBuyerService {

    @Autowired
    private MedicineBuyerMapper medicineBuyerMapper;
    @Autowired
    private MedicineStockMapper medicineStockMapper;

    @Override
    //添加进货信息，审核状态设置为0，未审核状态
    public void saveMedicineBuyer(MedicineBuyer medicineBuyer) {
        medicineBuyer.setStatus("0");//未审核
        medicineBuyerMapper.insert(medicineBuyer);
    }

    //审核
    @Override
    @Transactional
    public void examineMedicineBuyer(MedicineBuyer medicineBuyer) {
        if(medicineBuyer.getStatus().equals("0")){//不通过
            medicineBuyerMapper.deleteById(medicineBuyer.getId());
        }else {//通过
            //更新审核状态
            medicineBuyer.setStatus("1");
            medicineBuyerMapper.updateById(medicineBuyer);
            //新增库存
            MedicineStock medicineStock = new MedicineStock();
            medicineStock.setYid(medicineBuyer.getYid());
            medicineStock.setStocks(medicineBuyer.getStocks());
            medicineStock.setMusetime(medicineBuyer.getMusetime());
            medicineStock.setSremarks(medicineBuyer.getJyremarks());
            medicineStock.setYname(medicineBuyer.getYname());
            medicineStock.setStatus("1");//正常状态
            medicineStockMapper.insert(medicineStock);
        }
    }
}
